package al.softsynergy.auk.ui.ankesa;

import java.text.SimpleDateFormat;
import java.util.Date;

import al.softsynergy.auk.AukApplication;
import al.softsynergy.auk.data.containers.AnkesaContainer;
import al.softsynergy.auk.data.ejbs.IAukBean;
import al.softsynergy.auk.ui.utils.ColumnGeneratorUtils;

import com.vaadin.data.Property;
import com.vaadin.ui.Table;

public class AnkesaList extends Table {

	
	public AnkesaList(AnkesaUI ankesaUI){
		setSizeFull();
		this.setSizeUndefined();
		this.setWidth("100%");
		this.setContainerDataSource(ankesaUI.getDataSource());
		this.setVisibleColumns(AnkesaContainer.NATURAL_COL_ORDER);
		this.setColumnHeaders(AnkesaContainer.COL_HEADERS_ALBANIAN);
		this.setColumnCollapsingAllowed(true);
		this.setColumnReorderingAllowed(true);
		this.setPageLength(15);
		this.setSelectable(true);
		this.setImmediate(true);
		this.addListener((ValueChangeListener) ankesaUI);
		this.addGeneratedColumn("ankesaLloj", ColumnGeneratorUtils.ankesaLlojColumnGenerator());
		
	}
	
	public IAukBean getAukBean() {
		 return ((AukApplication)this.getApplication()).getAukBean();
	}

	@Override
	protected String formatPropertyValue(Object rowId, Object colId,
			Property property) {
		 Object v = property.getValue();
		 if (v instanceof Date) {
			 SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
			 return sdf.format(v);
		 }
		return super.formatPropertyValue(rowId, colId, property);
	}
	
	
	
	
	
}
